package orz.itrip;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {
    ///对象。方法（参数）
    public static String encodeStr(String oldString){
        try {
            MessageDigest md5=MessageDigest.getInstance("md5");
            byte [] bs=md5.digest(oldString.getBytes());
            //-128  127
//            System.out.println("打过后的："+new String(bs));
            StringBuilder sb=new StringBuilder();
            int temp=0;
            for(byte b: bs){
                temp=b;
                if(temp<0){
                    //加入
                    temp*=-2;
                }
                sb.append( Integer.toHexString(temp));
            }
//            System.out.println("加密后:"+sb.toString());
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}
